home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoWriteLargeNode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  6.7 KB  |  258 lines

  1. /*
  2.  *   $RCSfile: undoWriteLargeNode.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:04 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "latch.h"
  52. #include "semaphore.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "pool.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "trans.h"
  60. #include "logrecs.h"
  61. #include "logaction.h"
  62. #include "openlog.h"
  63. #include "undo.h"
  64. #include "undo_extfuncs.h"
  65. #include "bf_extfuncs.h"
  66. #include "log_extfuncs.h"
  67. #include "log_intfuncs.h"
  68. #include "util_funcs.h"
  69. #include "thread_globals.h"
  70. #include "bf_globals.h"
  71. #include "trans_globals.h"
  72. #include "sm_macro.h"
  73. #ifdef INIT_LRC_IS_LSN
  74. #    include "log_globals.h"
  75. #endif
  76.  
  77.  void
  78. undoWriteLargeNode(
  79.  
  80.     LOGRECORDHDR        *recordHeader 
  81. )
  82. {
  83.  
  84.     GROUPLINK            *groupLink;
  85.     LGNODE                *lgNode;
  86.     SLOTTEDPAGE         *slottedPage;
  87.     PAGETYPE            pageType;
  88.     PAGE2SIZE           page2size;
  89.     PAGESLOT            *slotPtr;
  90.     SMALLOBJ            *objPtr;
  91.     LRC                 *pageLRC;
  92.     LGNODEHDR            *oldNodeHdr;
  93.     PID                    *pid;
  94.     SLOTINDEX              rootSlot;
  95.     LOGRECORDINFO       recordInfo;
  96. #ifdef INIT_LRC_IS_LSN
  97.     LRC                 tempLRC;
  98.     LRC                 *lrc = &tempLRC;
  99. #else
  100.     LRC                 *lrc;
  101. #endif /* INIT_LRC_IS_LSN; */
  102.     LSN                    lsn;
  103.     FORCEMARK            forceMark;
  104.     BOOL                actionDone;    /* Indicates whether the action
  105.                                        was ever performed on the page */
  106.     INIT_MISSING_UPDATE_INFO( Active->transRec );
  107.  
  108.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN));
  109.  
  110.  
  111.     /*
  112.      *    get a pointer to the page for the record
  113.      */
  114.     pid = &(recordHeader->actionPid);
  115.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
  116.  
  117.     /*
  118.      *    get pointer to oid, header info
  119.      */
  120.     rootSlot = *(SLOTINDEX*) GET_LOG_IMAGE(recordHeader, 0);
  121.  
  122.     /*
  123.      *    get a pointer to the old data and its size in the record
  124.      */
  125.     oldNodeHdr = (LGNODEHDR*) GET_LOG_IMAGE(recordHeader, 2);
  126.  
  127.     /*
  128.      *    read in the page
  129.      */
  130.    if (rootSlot != NIL) {
  131.         pageType = PAGE_SLOTTED;
  132.         page2size = SLOTTED_PAGE2SIZE;
  133.     } else {
  134.         pageType = PAGE_LARGENODE;
  135.         page2size = LG_PAGE2SIZE;
  136.     }
  137.     if ((groupLink = bf_ReadPage(UserBufGroup, pid, page2size, BF_SEM)) == NULL) {
  138.  
  139.         SM_ERROR(TYPE_FATAL, Active->errno);
  140.     }
  141.     groupLink->pageHash->pageType = pageType;
  142.  
  143.     /*
  144.      *    get a pointer to the large node page
  145.      */
  146.     if (rootSlot == NIL) {
  147.         lgNode = (LGNODE *) groupLink->bufFrame;
  148.         pageLRC = &(lgNode->header.lrc);
  149.         CHECK_LARGENODE_MAGIC(lgNode);
  150.     } else {
  151.         /*
  152.          *  Root node on slotted page
  153.          */
  154.         slottedPage = (SLOTTEDPAGE *) groupLink->bufFrame;
  155.         pageLRC = &(slottedPage->header.lrc);
  156.         SM_ASSERT(LEVEL_3, !CHECK_SLOTTED_MAGIC(slottedPage));
  157.     }
  158.  
  159.     /*
  160.      *    See if the action was actually done
  161.      */ 
  162.     actionDone = compareLRC(&(recordHeader->actionLRC), pageLRC ) <= 0;
  163.     
  164.     /*
  165.      *    it is possible that the action 
  166.      *    never made it to the page on the server, so missing update
  167.      *    information may need to be recorded
  168.      *
  169.      *    Process any missing updates, and return a pointer to
  170.      *    the lrc to increment.  This will either be the lrc on the
  171.      *    slotted page, or the lrc in the missingUpdatePageTable
  172.      */
  173.     RECORD_MISSING_UPDATE( actionDone, &lrc, missingUpdateInfo, pid,
  174.                          pageLRC,
  175.                          groupLink->pageHash, recordHeader, PAGE_LARGENODE);
  176.  
  177.     /*
  178.      *    increment the lrc on the page
  179.      */
  180.     GENERATE_LRC(lrc);
  181.  
  182.     /*
  183.      *    Log the undo write
  184.      */
  185.     recordInfo.action       = LOG_ACTION_WRITE_LARGE_NODE;
  186.     recordInfo.type         = LOG_REC_TYPE_COMPENSATION;
  187.     recordInfo.imageCount   = 2;
  188.     recordInfo.actionPid    = pid;
  189.     recordInfo.actionLRC    = lrc;
  190.     recordInfo.imageSize[0] = sizeof(rootSlot);
  191.     recordInfo.imageData[0] = (VOID *) &rootSlot;
  192.     recordInfo.imageSize[1] = sizeof (*oldNodeHdr);
  193.     recordInfo.imageData[1] = (VOID *) oldNodeHdr;
  194.     recordInfo.nextUndoLSN  = recordHeader->previousLSN;
  195.     recordInfo.flags        = NOFLAGS;
  196.  
  197.     /*
  198.      *    write the record to the log
  199.      */
  200.     if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo,
  201.                               &lsn, NOFLAGS)) < 0)  {
  202.         SM_ERROR(TYPE_FATAL, Active->errno);
  203.     }
  204.  
  205.     /*
  206.      *    mark the page dependency
  207.      */
  208. #ifndef INIT_LRC_IS_LSN
  209.     DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  210. #endif
  211.  
  212.     /*
  213.      *    perform the undo, if the action was performed
  214.      */
  215.     if (actionDone) {
  216.  
  217. #ifdef INIT_LRC_IS_LSN
  218.         DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  219. #endif
  220.  
  221.         /*
  222.          *    get a pointer to the large node page
  223.          */
  224.         if (rootSlot != NIL) {
  225.             /*
  226.              *  Root node on slotted page
  227.              */
  228.             SM_ASSERT(LEVEL_3, rootSlot < slottedPage->header.slotCount);
  229.             slotPtr = GETSLOTPTR(slottedPage, rootSlot);
  230.             objPtr = GETOBJECTPTR(slottedPage, slotPtr);
  231.             lgNode = (LGNODE*) objPtr->data;
  232.             CHECK_SLOTROOT_MAGIC(lgNode);
  233.         }
  234.  
  235.         /*
  236.          *    Restore the old header, write fields separately to avoid
  237.          *    writing lrc field.
  238.          */
  239.         lgNode->header.magic = oldNodeHdr->magic;
  240.         lgNode->header.height = oldNodeHdr->height;
  241.         lgNode->header.numSlots = oldNodeHdr->numSlots;
  242.         lgNode->header.vhgPtr = oldNodeHdr->vhgPtr;
  243.  
  244.     }
  245.  
  246.     /*
  247.      *    signal the semaphore and unfix the page, dirty the page if
  248.      *    the action was done
  249.      */
  250.     signalSemaphore( &(groupLink->pageHash->semaphore) );
  251.     bf_UnfixPage(groupLink, BF_DEFAULT, actionDone);
  252.  
  253.     /*
  254.      *    return success
  255.      */
  256.     return;
  257. }
  258.